"""
# -*- coding: utf-8 -*-
# @Time    : 2023/3/3 18:59
# @Author  : 王摇摆
# @FileName: 三层神经网络.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import numpy as np


def sigmod(x):
    return 1 / (1 + np.exp(-x))


def identity_function(x):
    return x


def init_network():
    network = {}
    network['W1'] = np.array([[0.1, 0.3, 0.5], [0.2, 0.4, 0.6]])
    network['b1'] = np.array([0.1, 0.2, 0.3])
    network['W2'] = np.array([[0.1, 0.4], [0.2, 0.5], [0.3, 0.6]])
    network['b2'] = np.array([0.1, 0.2])
    network['W3'] = np.array([[0.1, 0.3], [0.2, 0.4]])
    network['b3'] = np.array([0.1, 0.2])

    return network


def forward(network, x):
    W1 = network['W1']
    W2 = network['W2']
    W3 = network['W3']

    b1 = network['b1']
    b2 = network['b2']
    b3 = network['b3']

    # 开始计算输出值
    a1 = np.dot(x, W1) + b1
    z1 = sigmod(a1)

    a2 = np.dot(z1, W2) + b2
    z2 = sigmod(a2)

    a3 = np.dot(z2, W3) + b3
    y = identity_function(a3)

    return y


# 程序入口
network = init_network()  # 构建网络
x = np.array([1, 0.5])
y = forward(network, x)  # 前向传播计算输出结果
print(y)
